<template>
    <div class="container">
      正在加载中...
    </div>
</template>
<script>
import axios from 'axios'
import {setCookie} from 'Utils/cookie'
import { Toast } from 'vant'
export default {
    data(){
        return {
            code:'',
        }
    },
    methods: {
        GetRequestParameters(locationsearch) {
    let url = locationsearch;
    let theRequest = new Object();
    if (url.indexOf("?") != -1) {
     let str = url.substr(1);
     let strs = str.split("&");
     for (let i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
     }
    }
    return theRequest;
   },
    check(){
        axios({
      url:'/hrkc/Approver/getOpenid',
      method:'POST',
      params:{
        code:this.code
        },
    }).then(res=>{
    console.log(res)
    if(res.data.code == 1){
       this.$router.push({
          path:'/login',
          query:{
              openid:res.data.openid.openid
          }
    
      })
    // this.$router.push('/login')
    }else if(res.data.code == 0){
         setCookie('org_no',res.data.org_no,7)
        setCookie('openid',res.data.openid,7)
        setCookie('approver_id',res.data.approver_id,7)
        setCookie('approver_name',res.data.approver_name,7)
        setCookie('grade_id',res.data.grade_id,7)
        this.$router.push('/select')
    }
     
    }).catch(err=>{
        Toast.fail('请求失败');
          this.$router.push('/login')
    })
    }
    },
    mounted(){
          let tmpUrlSearch = window.location.search; // 得到：?sceneid=h5&wxcode=xxx&puid=fff
            let tmpParas = this.GetRequestParameters(tmpUrlSearch);
            this.code = tmpParas["code"]; //提取参数
            this.check()
    }
    
   

}
</script>